package com.vgooo.util;

import java.io.File;

import com.vgooo.client.VGApplication;

import android.os.Environment;
import android.os.StatFs;

/**
 * 处理文件的工具类
 * @author Administrator
 *
 */
public class FileUtils {
	/**
	 * 获取外部存储器sdcard文件路径
	 * @return File
	 */
	public static File getExterSgetExternalStorageFile(){
		if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
			return Environment.getExternalStorageDirectory() ;
		}else {
//			return Environment.getDataDirectory();
			return null ;
		}
	}
	
	
	/**
	 * 
	 * @param path File 文件路径
	 * 
	 * @return StatFs  文件的相关信息
	 */
	public static StatFs getSstatFs(File path){
		return new StatFs( path.getPath());
	}
	
	/**
	 * 获取sd卡空间大小
	 * @return long 可用空间大小 单位 bit
	 */
	public static long getAvailaleSize(File sdcardFile){
		StatFs statfs = getSstatFs(sdcardFile);
		/*获取block的size*/
		long blockSize = statfs.getBlockSize() ;
		
		/*获取空闲Block的数量*/
		long availableBlocks = statfs.getAvailableBlocks() ;
		
		/*返回可bit大小*/
		return availableBlocks * blockSize ;
		
		//(availableBlocks * blockSize)/1024      KIB 单位
		//(availableBlocks * blockSize)/1024 /1024  MIB单位

	}
	
	
	/**
	 * sd卡大小
	 * @return long 单位bit
	 */
	public static long getAllSize(File filePath){
		StatFs stat = getSstatFs(filePath);
		
		/*获取block的SIZE*/

		long blockSize = stat.getBlockSize(); 

		/*块数量*/

		long availableBlocks = stat.getBlockCount();

		/* 返回bit大小值*/

		return availableBlocks * blockSize; 

	}
}
